/*
 * DILARANG MENGHAPUS ATAU MENGEDIT COPYRIGHT INI.
 * 
 * Copyright 2008 echo.khannedy@gmail.com. 
 * All rights reserved.
 * 
 * Semua isi dalam file ini adalah hak milik dari echo.khannedy@gmail.com
 * Anda tak diperkenankan untuk menggunakan file atau mengubah file
 * ini kecuali anda tidak menghapus atau merubah lisence ini.
 * 
 * File ini dibuat menggunakan :
 * IDE        : NetBeans
 * NoteBook   : Acer Aspire 5920G
 * OS         : Windows Vista
 * Java       : Java 1.6
 */
package usu.perpustakaan.buku.widget.operator;

import java.util.Date;
import javax.swing.JTable;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import usu.perpustakaan.buku.widget.admin.ManageOperator;
import usu.perpustakaan.buku.widget.template.TableModelReturn;
import usu.perpustakaan.buku.widget.template.TextBoxGlass;
import usu.widget.ButtonGlass;
import usu.widget.util.WidgetUtilities;

/**
 *
 * @author  usu
 */
public class ManageReturnReport extends javax.swing.JPanel {

    private static final long serialVersionUID = -1;
    private TableModelReturn model;

    /** Creates new form ManageBorrow */
    public ManageReturnReport() {
        initVariables();
        initComponents();
        initFinal();
        initActions();
    }

    /**
     * 
     * @return
     */
    public ButtonGlass getButtonFilter() {
        return buttonFilter;
    }

    /**
     * 
     * @param b
     */
    public void setFreeze(boolean b) {
        textSearch.setEnabled(!b);
        buttonRefresh.setEnabled(!b);
        table.setEnabled(!b);
    }

    private void initActions() {
        textSearch.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                filterTable(textSearch.getText());
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                filterTable(textSearch.getText());
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                filterTable(textSearch.getText());
            }
        });
    }

    /**
     * 
     * @param text
     */
    @SuppressWarnings("unchecked")
    public void filterTable(String text) {
        if (text.trim().equals("")) {
            ((TableRowSorter<TableModel>) table.getRowSorter()).setRowFilter(null);
        } else {
            ((TableRowSorter<TableModel>) table.getRowSorter()).setRowFilter(RowFilter.regexFilter(text));
        }
    }

    /**
     * 
     * @return
     */
    public Date getDateUntil() {
        if (!textUntil.isEnabled()) {
            return null;
        }
        return (Date) textUntil.getValue();
    }

    /**
     * 
     * @return
     */
    public Date getDateFrom() {
        if (!textFrom.isEnabled()) {
            return null;
        }
        return (Date) textFrom.getValue();
    }

    /**
     * 
     * @return
     */
    public String getMemberId() {
        if (!textMember.isEnabled()) {
            return null;
        }
        return textMember.getText();
    }

    /**
     * 
     * @return
     */
    public String getBookId() {
        if (!textBuku.isEnabled()) {
            return null;
        }
        return textBuku.getText();
    }

    /**
     * 
     * @return
     */
    public String getOperatorId() {
        if (!textOperator.isEnabled()) {
            return null;
        }
        return textOperator.getText();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        usu.perpustakaan.buku.widget.template.ViewPortGlass viewPortGlass1 = new usu.perpustakaan.buku.widget.template.ViewPortGlass();
        table = new javax.swing.JTable();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        textSearch = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
        buttonRefresh = new usu.widget.ButtonGlass();
        buttonFilter = new usu.widget.ButtonGlass();
        usu.perpustakaan.buku.widget.template.PanelTranparan panelTranparan1 = new usu.perpustakaan.buku.widget.template.PanelTranparan();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        textUntil = new usu.perpustakaan.buku.widget.template.FormatedTextBox();
        textFrom = new usu.perpustakaan.buku.widget.template.FormatedTextBox();
        textBuku = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        textOperator = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        textMember = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        cekUntil = new javax.swing.JCheckBox();
        cekFrom = new javax.swing.JCheckBox();
        cekBook = new javax.swing.JCheckBox();
        cekOperator = new javax.swing.JCheckBox();
        cekMember = new javax.swing.JCheckBox();

        viewPortGlass1.setView(table);

        table.setAutoCreateRowSorter(true);
        table.setForeground(new java.awt.Color(255, 255, 255));
        table.setFillsViewportHeight(true);
        table.setOpaque(false);
        table.setSelectionBackground(new java.awt.Color(51, 255, 52));
        table.setSelectionForeground(new java.awt.Color(0, 0, 0));

        setOpaque(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Cari (case sensitive) ");

        textSearch.setForeground(new java.awt.Color(255, 255, 255));
        textSearch.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textSearch.setFont(new java.awt.Font("Tahoma", 1, 11));

        jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane1.setOpaque(false);
        jScrollPane1.setViewport(viewPortGlass1);

        buttonRefresh.setText("Segarkan");
        buttonRefresh.setRoundRect(true);

        buttonFilter.setText("Saring");
        buttonFilter.setRoundRect(true);

        panelTranparan1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panelTranparan1.setOpaqueImage(false);
        panelTranparan1.setRound(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Id Anggota");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Id Operator");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Id Buku");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Dari Tanggal");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Sampai Tanggal");

        textUntil.setForeground(new java.awt.Color(255, 255, 255));
        textUntil.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textUntil.setFont(new java.awt.Font("Tahoma", 1, 11));
        textUntil.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        textUntil.setValue(new java.util.Date());

        textFrom.setForeground(new java.awt.Color(255, 255, 255));
        textFrom.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textFrom.setFont(new java.awt.Font("Tahoma", 1, 11));
        textFrom.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        textFrom.setValue(new java.util.Date());

        textBuku.setForeground(new java.awt.Color(255, 255, 255));
        textBuku.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textBuku.setFont(new java.awt.Font("Tahoma", 1, 11));

        textOperator.setForeground(new java.awt.Color(255, 255, 255));
        textOperator.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textOperator.setFont(new java.awt.Font("Tahoma", 1, 11));

        textMember.setForeground(new java.awt.Color(255, 255, 255));
        textMember.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textMember.setFont(new java.awt.Font("Tahoma", 1, 11));

        cekUntil.setSelected(true);
        cekUntil.setOpaque(false);
        cekUntil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cekUntilActionPerformed(evt);
            }
        });

        cekFrom.setSelected(true);
        cekFrom.setOpaque(false);
        cekFrom.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cekFromItemStateChanged(evt);
            }
        });

        cekBook.setSelected(true);
        cekBook.setOpaque(false);
        cekBook.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cekBookItemStateChanged(evt);
            }
        });

        cekOperator.setSelected(true);
        cekOperator.setOpaque(false);
        cekOperator.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cekOperatorItemStateChanged(evt);
            }
        });

        cekMember.setSelected(true);
        cekMember.setOpaque(false);
        cekMember.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cekMemberItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout panelTranparan1Layout = new javax.swing.GroupLayout(panelTranparan1);
        panelTranparan1.setLayout(panelTranparan1Layout);
        panelTranparan1Layout.setHorizontalGroup(
            panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTranparan1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textMember, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addComponent(textOperator, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addComponent(textBuku, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addComponent(textFrom, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addComponent(textUntil, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cekUntil)
                    .addComponent(cekFrom)
                    .addComponent(cekBook)
                    .addComponent(cekOperator)
                    .addComponent(cekMember))
                .addContainerGap())
        );
        panelTranparan1Layout.setVerticalGroup(
            panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTranparan1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(textMember, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekMember))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(textOperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekOperator))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(textBuku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekBook))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(textFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekFrom))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTranparan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(textUntil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cekUntil))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
                    .addComponent(panelTranparan1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(buttonRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 456, Short.MAX_VALUE)
                        .addComponent(buttonFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTranparan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );
    }// </editor-fold>//GEN-END:initComponents

private void cekMemberItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cekMemberItemStateChanged
    textMember.setEnabled(cekMember.isSelected());
}//GEN-LAST:event_cekMemberItemStateChanged

private void cekOperatorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cekOperatorItemStateChanged
    textOperator.setEnabled(cekOperator.isSelected());
}//GEN-LAST:event_cekOperatorItemStateChanged

private void cekBookItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cekBookItemStateChanged
    textBuku.setEnabled(cekBook.isSelected());
}//GEN-LAST:event_cekBookItemStateChanged

private void cekFromItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cekFromItemStateChanged
    textFrom.setEnabled(cekFrom.isSelected());
}//GEN-LAST:event_cekFromItemStateChanged

private void cekUntilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cekUntilActionPerformed
    textUntil.setEnabled(cekUntil.isSelected());
}//GEN-LAST:event_cekUntilActionPerformed

    private void initFinal() {
        table.setModel(model);
        for (int i = 0; i < table.getColumnCount(); i++) {
            table.getColumnModel().getColumn(i).setCellRenderer(new ManageOperator.RenderTable());
        }
        WidgetUtilities.setAutomaticPopUpMenu(table);
    }

    /**
     * 
     * @return
     */
    public TableModelReturn getModel() {
        return model;
    }

    /**
     * 
     * @return
     */
    public ButtonGlass getButtonRefresh() {
        return buttonRefresh;
    }

    /**
     * 
     * @return
     */
    public JTable getTable() {
        return table;
    }

    /**
     * 
     * @return
     */
    public TextBoxGlass getTextSearch() {
        return textSearch;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    usu.widget.ButtonGlass buttonFilter;
    usu.widget.ButtonGlass buttonRefresh;
    javax.swing.JCheckBox cekBook;
    javax.swing.JCheckBox cekFrom;
    javax.swing.JCheckBox cekMember;
    javax.swing.JCheckBox cekOperator;
    javax.swing.JCheckBox cekUntil;
    javax.swing.JTable table;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textBuku;
    usu.perpustakaan.buku.widget.template.FormatedTextBox textFrom;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textMember;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textOperator;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textSearch;
    usu.perpustakaan.buku.widget.template.FormatedTextBox textUntil;
    // End of variables declaration//GEN-END:variables

    private void initVariables() {
        model = new TableModelReturn();
    }
}
